<?php
class Cserver{
	
    public static function getDomain($http='http'){
        if(80==$_SERVER['SERVER_PORT']||8080==$_SERVER['SERVER_PORT']){
            $server_port_str='';
        }else{
            $server_port_str=':'.$_SERVER['SERVER_PORT'];
        }
        return $http.'://'.$_SERVER['SERVER_NAME'].$server_port_str.'/';
    }
	
	//格式化左斜杠
	public static function changeFilenameSlashs ($file=""){   
        return preg_replace('/\/{1,}/', '/', str_replace ('\\','/',  $file ));
    }
	
    public static function file2url( $__file__){
        $_DOCUMENT_ROOT= self::changeFilenameSlashs( $_SERVER['DOCUMENT_ROOT'] ).'/';
		$__file__      = self::changeFilenameSlashs( $__file__ ) ;
        return str_replace($_DOCUMENT_ROOT,self::getDomain(), $__file__) ;    
   }
   	
}
//echo Cserver::file2url(__FILE__);
?>